<template>
  <div class="addPatient">
    <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
      <Row>
        <Col span="24">
        <FormItem label="姓名" prop="username">
          <Input v-model="formValidate.username" placeholder="请输入用户名"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="性别" prop="sex">
          <RadioGroup v-model="formValidate.sex">
            <Radio label="男">男</Radio>
            <Radio label="女">女</Radio>
          </RadioGroup>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="电话" prop="phone">
          <Input v-model="formValidate.phone" placeholder="请输入手机号"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="年龄" prop="age">
          <Input v-model="formValidate.age" placeholder="请输入年龄"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="民族" prop="nation">
          <Input v-model="formValidate.nation" placeholder="请输入民族"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="邮箱" prop="email">
          <Input v-model="formValidate.email" placeholder="请输入邮箱"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="身份证" prop="idCard">
          <Input v-model="formValidate.idCard" placeholder="请输入身份证"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="症状" prop="symptom">
          <Input v-model="formValidate.symptom" placeholder="请输入症状"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="诊断结果" prop="result">
          <Input v-model="formValidate.result" placeholder="请输入诊断结果"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="家庭住址" prop="address">
          <Input v-model="formValidate.address" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入您的家庭住址"></Input>
        </FormItem>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <FormItem label="备注" prop="remark">
          <Input v-model="formValidate.remark" placeholder="请输入用备注"></Input>
        </FormItem>
        </Col>
      </Row>
    </Form>
  </div>
</template>

<script>
import patient from "@/api/patientFile.js";
export default {
  data() {
    return {
      formValidate: {
        username: "",
        phone: "",
        sex: "",
        age: "",
        nation: "",
        email: "",
        idCard: "",
        symptom: "",
        result: "",
        remark: "",
        address: ""
      },
      ruleValidate: {
        username: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        sex: [{ required: true, message: "请选择性别", trigger: "blur" }],
        phone: [
          {
            required: true,
            message: "为了方便联系，号码不能为空",
            trigger: "blur"
          }
        ],
        age: [{ required: true, message: "年龄不能为空", trigger: "blur" }],
        nation: [{ required: true, message: "民族不能为空", trigger: "blur" }],
        email: [{ required: true, message: "邮箱不能为空", trigger: "change" }],
        idCard: [
          { required: true, message: "省份证号码不能为空", trigger: "change" }
        ],
        symptom: [
          { required: true, message: "症状不能为空", trigger: "change" }
        ],
        result: [
          { required: false, message: "诊断结果不能为空", trigger: "change" }
        ],
        address: [
          { required: true, message: "家庭住址不能为空", trigger: "change" }
        ],
        remark: [
          {
            required: false,
            type: "string",
            message: "症状不能为空",
            trigger: "change"
          }
        ]
      }
    };
  },
  methods: {
    handleSubmit() {
      return new Promise((res, rej) => {
        this.$refs["formValidate"].validate(valid => {
          if (valid) {
            patient.addPatient({ ...this.formValidate }).then(data => {
              if (data.flag) {
                this.$Message.success("Success!");
                res(data);
              }else{
                rej();
              }
            });
          } else {
            this.$Message.error("在检查一下");
            rej();
          }
        });
      });
    }
  }
};
</script>

<style lang="less" scoped>
.addPatient {
  form {
    padding-left: 50px;
    padding-right: 80px;
  }
}
</style>
